﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using System.IO;

namespace Chapter02_Lesson01
{
    class Program
    {
        static void Main(string[] args)
        {
            try
            {
                //foreach (DriveInfo driver in DriveInfo.GetDrives())
                //{
                //    if (driver.IsReady)
                //        Console.WriteLine("Name {0}, Type {1}, Avaible Space = {2}, Format {3}.", driver.Name, driver.DriveType, driver.AvailableFreeSpace, driver.DriveFormat);
                //}

                //DirectoryInfo dir = new DirectoryInfo("C:\\");

                //Console.WriteLine("Folders:");

                //foreach (DirectoryInfo directory in dir.GetDirectories())
                //{
                //    Console.WriteLine("The directory {0} was last accessed at {1}.", directory.Name, directory.LastAccessTimeUtc);

                //    Console.WriteLine("All the txt files in this folder:");

                //    foreach (FileInfo file in directory.GetFiles())
                //    {
                //        Console.WriteLine(file.Name);
                //    }
                //}

                FileSystemWatcher fw = new FileSystemWatcher("C:\\");
                fw.IncludeSubdirectories = false;
                fw.NotifyFilter = NotifyFilters.FileName | NotifyFilters.Security;
                fw.Changed += new FileSystemEventHandler(fw_Changed);
                fw.EnableRaisingEvents = true;
            }
            catch (IOException ex)
            {
                Console.WriteLine("The driver is not ready");
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }

        static void fw_Changed(object sender, FileSystemEventArgs e)
        {
            Console.WriteLine("The file {0} in the directory {1} has been changed.", e.Name, e.FullPath);
        }
    }
}
